package com.example.lcode.backtrack;

import java.util.ArrayList;
import java.util.List;

public class Question77 {

    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> res = new ArrayList<>();
        int startIndex = 1;
        List<Integer> subRes = new ArrayList<>();
        combine(n, k, res, subRes, startIndex);
        return res;
    }

    private void combine(int n, int k, List<List<Integer>> res, List<Integer> subRes, int startIndex) {
        if (subRes.size() == k) {
            res.add(new ArrayList<>(subRes));
            return;
        }
        for (int i = startIndex; i <= n; i++) {
            subRes.add(i);
            combine(n, k, res, subRes, i + 1);
            subRes.remove(subRes.size() - 1);
        }
    }

    public static void main(String[] args) {
        Question77 question77 = new Question77();
        int number = 1;
        int limit = 1;
        List<List<Integer>> combine = question77.combine(number, limit);
        System.out.println(combine);
    }

}
